<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/***
 * 通用化API接口书输出
 * @param int $status 业务状态码
 * @param string $message 信息提示
 * @param array $data 数组
 * @param int $httpCode http状态码
 * @return array
 */
function show($status,$message,$data = [], $httpCode = 200){
    $data = [
        'status' => $status,
        'message' => $message,
        'data' => $data,
    ];
//    return  json($data,$httpCode);
    echo json_encode($data,$httpCode);die;
}

function show1($status,$message,$data = [], $httpCode = 200){
    $data = [
        'status' => $status,
        'message' => $message,
        'data' => $data,
    ];
    return  json($data,$httpCode);
//    echo json_encode($data,$httpCode);die;
}

//根据生日算年龄

function birthday($birthday){
//    $age = strtotime($birthday);
//    if($age === false){
//        return false;
//    }
    list($y1,$m1,$d1) = explode("-",date("Y-m-d",$birthday));
    $now = strtotime("now");
    list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
    $age = $y2 - $y1;
    if((int)($m2.$d2) < (int)($m1.$d1))
        $age -= 1;
    return $age;
}

